from UIAutoTest.unittest_crud.废弃.PublicClass import PublicClass
import time


# 添加文章的测试代码
class AddArticle(PublicClass):
    # 定义初始化方法
    def __init__(self):
        # 获取driver 打开在线商城网页
        PublicClass.__init__(self)
        time.sleep(1)
        # 进入文章管理页面
        self.driver.get('http://shop-xo.hctestedu.com/admin.php?s=/article/index.html')
#     # 定位元素层
#
#
# class FindElement(AddArticle):
#     def __init__(self):
#         AddArticle.__init__(self)
#
#     # 定位元素
#     def find_element_a(self):
#         return self.driver.find_element_by_css_selector(
#             'a[href="http://shop-xo.hctestedu.com/admin.php?s=/article/saveinfo.html"]')
#
#     def find_element_title(self):
#         return self.driver.find_element_by_name('title')
#
#     def find_element_jump_url(self):
#         return self.driver.find_element_by_name('jump_url')
#
#     def find_element_div4(self):
#         return self.driver.find_element_by_xpath(
#             '//div[@class="content"]/form/div[4]//div[@class="am-switch-container"]')
#
#     def find_element_div5(self):
#         return self.driver.find_element_by_xpath(
#             '//div[@class="content"]/form/div[5]//div[@class="am-switch-container"]')
#
#     def find_element_content(self):
#         iframe_element = self.driver.find_element_by_xpath('//div[@id="edui1_iframeholder"]/iframe')
#         self.driver.switch_to_frame(iframe_element)
#         return self.driver.find_element_by_xpath('//body[@class="view"]/p')
#
#
# # 操作层
# class ElementHandle(FindElement):
#     def __init__(self):
#         FindElement.__init__(self)
#
#     def get_a(self):
#         FindElement.find_element_a().click()
#
#     def get_title(self, title):
#         FindElement.find_element_title().send_keys(title)
#
#     def get_jump_url(self, url):
#         FindElement.find_element_jump_url().send_keys(url)
#
#     def get_div4(self):
#         FindElement.find_element_div4().click()
#
#     def get_div5(self):
#         FindElement.find_element_div5().click()
#
#     def get_content(self, content):
#         FindElement.find_element_content().send_keys(content)

    # 添加文章3


# # 业务层
# class Service(ElementHandle):
#     def __init__(self):
#         ElementHandle.__init__(self)
#
#     def add_article(self, title, url, content):
#         self.get_a()
#         self.find_element_title(title)
#         self.get_jump_url(url)
#         self.get_div4()
#         self.get_div5()
#         self.find_element_content(content)

    # def add_article(self, title, url, content):
    #     # 定位新增按钮
    #     self.driver.find_element_by_css_selector(
    #         'a[href="http://shop-xo.hctestedu.com/admin.php?s=/article/saveinfo.html"]').click()
    #     time.sleep(1)
    #     # 定位标题
    #     self.driver.find_element_by_name('title').send_keys(title)
    #     time.sleep(1)
    #     # 定位url地址
    #     self.driver.find_element_by_name('jump_url').send_keys(url)
    #     time.sleep(1)
    #     # 定位是否启用
    #     self.driver.find_element_by_xpath(
    #         '//div[@class="content"]/form/div[4]//div[@class="am-switch-container"]').click()
    #     time.sleep(1)
    #     # 定位首页推荐
    #     self.driver.find_element_by_xpath(
    #         '//div[@class="content"]/form/div[5]//div[@class="am-switch-container"]').click()
    #     time.sleep(1)
    #     # 定位内容  由于存在iframe表单，需要进行表单切换
    #     iframe_element = self.driver.find_element_by_xpath('//div[@id="edui1_iframeholder"]/iframe')
    #     self.driver.switch_to_frame(iframe_element)
    #     self.driver.find_element_by_xpath('//body[@class="view"]/p').send_keys(content)
    #     time.sleep(1)
